package cn.stronglink.assetmanage.business.search.view.AssisChange;

import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.entity.Asset;
import cn.stronglink.assetmanage.entity.Brand;
import cn.stronglink.assetmanage.entity.Room;
import cn.stronglink.assetmanage.entity.SearchAsset;
import cn.stronglink.assetmanage.entity.Type;
import cn.stronglink.assetmanage.utils.ImageUtils;
import cn.stronglink.assetmanage.utils.ToastUtil;

/**
 * 变更资产界面
 * Created by zhengjinglan on 2018/6/19.
 */

public class AssisChangeView {
    private Fragment fragment;
//    @BindView(R.id.tv_search_asset_name)
//    EditText tv_search_asset_name;
//    @BindView(R.id.sp_search_location)
//    Spinner sp_search_location;
//    @BindView(R.id.sp_brand_name)
//    Spinner sp_brand_name;
//    @BindView(R.id.sp_search_asset_class)
//    Spinner sp_search_asset_class;
//    @BindView(R.id.tv_search_model)
//    EditText tv_search_model;
//    @BindView(R.id.tv_search_sn_no)
//    TextView tv_check_sn_no;
//    @BindView(R.id.tv_search_rfid_no)
//    TextView tv_search_rfid_no;
//    @BindView(R.id.iv_search_picture)
//    ImageView iv_search_picture;
    private Asset asset;

    public AssisChangeView(Fragment fragment, View view) {
        this.fragment = fragment;
        ButterKnife.bind(this, view);
    }

    /**
     * 设置资产信息
     *
     * @param asset
     * @param bm
     */
    public void showAssetDetail(SearchAsset asset, long roomIndex, long brandIndex, long typeIndex, Bitmap bm) {
//        tv_search_asset_name.setText(asset.getAssetName());
//        tv_search_model.setText(asset.getModelName());
//        tv_check_sn_no.setText(asset.getSerialNo());
//        tv_search_rfid_no.setText(asset.getRfidNo());
//        sp_search_location.setSelection(Integer.valueOf(roomIndex + ""));
//        sp_brand_name.setSelection(Integer.valueOf(brandIndex + ""));
//        sp_search_asset_class.setSelection(Integer.valueOf(typeIndex + ""));
//        iv_search_picture.setImageBitmap(bm);
    }

    public Asset saveAssetDetail(Asset preAsset) {
//        asset.setAssetName(tv_search_asset_name.getText().toString());
//        asset.setModelName(tv_search_model.getText().toString());
//        asset.setSerialNo(tv_check_sn_no.getText().toString());
//        asset.setRfidNo(tv_search_rfid_no.getText().toString());
        if (preAsset != null) {
            asset.setRoomName(preAsset.getRoomName());
            asset.setBrandName(preAsset.getBrandName());
            asset.setTypeName(preAsset.getTypeName());
            asset.setPictureUri(preAsset.getPictureUri());
            //需要将图片通过base64转为json串
            asset.setImagpath(ImageUtils.imageToBase64(preAsset.getPictureUri()));
        }
        return asset;
    }

    public void startActivityForPicture(int pictureUrl) {
        Intent intent = new Intent("android.intent.action.GET_CONTENT");
        intent.setType("image/*");
        fragment.startActivityForResult(intent, pictureUrl);
    }

    /**
     * 显示资产图片
     *
     * @param pictureUrl
     */
    public void showAssetPicture(String pictureUrl) {
//        iv_search_picture.setImageBitmap(ImageUtils.getIntance().getBitMBitmap(pictureUrl));
    }

    public void showProgressDialog(String msg) {

    }

    public void hideProgressDialog() {

    }

    public void showToast(String msg) {
        ToastUtil.toastShort(msg);
    }
}
